/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.x.component.connectivity;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class WifiState extends ConnectivityState {

    public String ssid = null;
    public boolean isTransient = false;
    public boolean isDefault = false;
    public String statusLabel = null;
    public boolean isCarrierMerged = false;
    public int subId = 0;
    public int wifiStandard = 0;
    public boolean isReady = false;

    @Override
    public void copyFrom(ConnectivityState s) {
        super.copyFrom(s);
        if (s instanceof WifiState) {
            WifiState state = (WifiState) s;
            this.ssid = state.ssid;
            this.isTransient = state.isTransient;
            this.isDefault = state.isDefault;
            this.statusLabel = state.statusLabel;
            this.isCarrierMerged = state.isCarrierMerged;
            this.subId = state.subId;
            this.wifiStandard = state.wifiStandard;
            this.isReady = state.isReady;
        }
    }

    @Override
    protected void toString(StringBuilder builder) {
        super.toString(builder);
        builder.append(",ssid=").append(ssid)
                .append(",wifiStandard=").append(wifiStandard)
                .append(",isReady=").append(isReady)
                .append(",isTransient=").append(isTransient)
                .append(",isDefault=").append(isDefault)
                .append(",statusLabel=").append(statusLabel)
                .append(",isCarrierMerged=").append(isCarrierMerged)
                .append(",subId=").append(subId);
    }

    @Override
    protected List<String> tableColumns() {
        List<String> columns = Arrays.asList(
                "ssid",
                "isTransient",
                "isDefault",
                "statusLabel",
                "isCarrierMerged",
                "subId"
        );
        List<String> parentColumns = super.tableColumns();
        List<String> combinedColumns = new ArrayList<String>(parentColumns);
        combinedColumns.addAll(columns);
        return combinedColumns;
    }

    @Override
    protected List<String> tableData() {
        List<String> data = Arrays.asList(
                ssid,
                Boolean.toString(isTransient),
                Boolean.toString(isDefault),
                statusLabel,
                Boolean.toString(isCarrierMerged),
                Integer.toString(subId)
        );
        List<String> parentData = super.tableData();
        List<String> combinedData = new ArrayList<String>(parentData);
        combinedData.addAll(data);
        return combinedData;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;

        WifiState wifiState = (WifiState) o;

        if (isTransient != wifiState.isTransient) return false;
        if (isDefault != wifiState.isDefault) return false;
        if (isCarrierMerged != wifiState.isCarrierMerged) return false;
        if (subId != wifiState.subId) return false;
        if (wifiStandard != wifiState.wifiStandard) return false;
        if (isReady != wifiState.isReady) return false;
        if (ssid != null ? !ssid.equals(wifiState.ssid) : wifiState.ssid != null) return false;
        return statusLabel != null ? statusLabel.equals(wifiState.statusLabel) : wifiState.statusLabel == null;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + (ssid != null ? ssid.hashCode() : 0);
        result = 31 * result + Boolean.hashCode(isTransient);
        result = 31 * result + Boolean.hashCode(isDefault);
        result = 31 * result + (statusLabel != null ? statusLabel.hashCode() : 0);
        result = 31 * result + Boolean.hashCode(isCarrierMerged);
        result = 31 * result + subId;
        result = 31 * result + wifiStandard;
        result = 31 * result + Boolean.hashCode(isReady);
        return result;
    }
}
